class Solution:
    def longestDiverseString(self, a: int, b: int, c: int) -> str:
        def get(array, e):
            ev = ord(e) - ord('a') if e is not None else -1
            res = -1
            maxVal = 0
            index = -1
            for i in range(len(array)):
                if maxVal < array[i] and ev != i:
                    res = i
                    maxVal = array[i]
                    index = i

            if index >= 0:
                array[index] -= 1
            return chr(ord('a') + res) if res != -1 else None

        array = [a, b, c]
        res = ''
        last = (None, 0)
        while True:
            lastChar, times = last
            char = get(array, lastChar if times >= 2 else None)
            if char is None:
                break
            res += char
            if char == lastChar:
                last = (char, 2)
            else:
                last = (char, 1)

        return res
